package com.ash.controller.type;

import com.alibaba.fastjson.JSONObject;
import com.ash.domain.Type;
import com.ash.service.type.TypeService;
import com.ash.util.JsonUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author : Chen Chao
 * @encoding : UTF-8
 * @date : 2021/3/25 17:11
 * @file : project06.com.ash.controller.book.Type.java
 * @software : IntelliJ IDEA
 * @since : 1.8
 */
@Controller
public class TypeController {
    @Resource
    TypeService typeService;
    @RequestMapping("/type/typeEdit")
    public String typeEdit(){
        return "admin/typeEdit";
    }
    @RequestMapping("/type/selectAll")
    @ResponseBody
    public String selectAll(@RequestParam("page") Integer page, @RequestParam("limit") Integer limit) {
        return JsonUtil.getJsonList(typeService.dataCount(),typeService.selectAll(page, limit));
    }
    @RequestMapping("/type/deleteById")
    public Integer deleteById(@RequestParam("tid") Integer tid){
        return typeService.deleteById(tid);
    }
    @PostMapping("/type/deleteByIds")
    public Integer deleteByIds(@RequestParam("ids") List<Integer> ids){
        return typeService.deleteByIds(ids);
    }
    @RequestMapping("/type/addForm")
    public String addform(){
        return "forward:/WEB-INF/jsp/admin/addForm.html";
    }
    @RequestMapping("/type/add")
    @ResponseBody
    public Integer add(@RequestParam("tname") String tname){
        return typeService.add(tname);
    }
    @RequestMapping("/type/update")
    @ResponseBody
    public int  update(Type type){
        return typeService.update(type);
    }
}
